/**
 * 
 */
package com.lmx.persistence.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Service;

import com.lmx.common.util.CommonUtil;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.SalaryReport;
import com.lmx.repoDomain.tmodel.Tenant;

/**
 * 薪资月统计Service实现
 * @author  djs
 * 2018年4月3日
 */
@Service(value = "salaryReportService")
public class SalaryReportServiceImpl extends BaseCrudServiceImpl<SalaryReport> implements SalaryReportService{
	@PersistenceContext
	private EntityManager em;
	@SuppressWarnings("unchecked")
	public List<SalaryReport> findSalaryReport(String year, String month){
		StringBuilder salaryReportSql = new StringBuilder("select sr from SalaryReport sr where sr.year =?1 and sr.month =?2 and sr.delStatus != 1");
		//月份直接用Calendar.getInstance().get(Calendar.MONTH)，Calendar月份从0~11。因为是获取上个月份所以直接用就行了。
		List<SalaryReport> salaryReports = this.em.createQuery(salaryReportSql.toString()).setParameter(1, Integer.valueOf(year)).setParameter(2, Integer.valueOf(month))
			.getResultList();
	return salaryReports;

	}
	@Override
	public SalaryReport receiveInitSalaryReport(Tenant tenant, String year, String month, int[] count) {
		SalaryReport salaryReport = new SalaryReport();
		salaryReport.setEntryCount(count[0]);//790试用
		salaryReport.setDimissionCount(count[1]);//140离职
		salaryReport.setPayOffCount(count[0]+count[1]+count[2]);//开支人数=试用人数+离职人数+正式人数
		salaryReport.setYear(Integer.valueOf(year));//所属年份
		salaryReport.setMonth(Integer.valueOf(month));//所属月份，Calendar月份是从0~11表示1~12月
		salaryReport.setTenant(tenant);//所属租户
		salaryReport.setCreateDateTime(CommonUtil.getCurrTimes());//创建时间
		salaryReport.setLastUpdateDateTime(CommonUtil.getCurrTimes());//最后修改时间
		salaryReport.setDelStatus((short)0);//有效标识，默认0有效
		return salaryReport;
	}
}
